﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public static partial class Tools
{
    /// <summary>
    /// 根据方向选择下一个Selectable
    /// </summary>
    public static void SelectNext(Vector2 direction)
    {
        var gameObject = EventSystem.current.currentSelectedGameObject;
        if (gameObject == null) return;
        var selectable = gameObject.GetComponent<Selectable>();
        var nextSelectable = selectable.FindSelectable(direction);
        if (nextSelectable == null) return;
        EventSystem.current.SetSelectedGameObject(nextSelectable.gameObject);
    }
}